		TITLE	LISTINIT - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	IO_STRUC

		PUBLIC	LIST_INIT


		.DATA

		EXTERNDEF	_FILE_LIST_GARRAY:STD_PTR_S,OUTFILE_GARRAY:STD_PTR_S

		EXTERNDEF	LOUTALL:DWORD,IMP_OUTALL:DWORD


		.CODE	ROOT_TEXT

		EXTERNDEF	_open_output:proc,_flush_buffer:proc,LST_OUT:PROC,ROOT_RET:PROC,IMP_OUT:PROC


LIST_INIT	PROC
		;
		;EAX IS OUTFILE GINDEX
		;
		;RETURNS:
		;	EAX IS OUTPUT DEVICE
		;
		;SET UP OUTPUT STUFF FOR LISTING
		;FIRST, IF LISTING DEVICE IS NUL, SET JMP TABLE TO 'RET'
		;ELSE IF DEVICE IS CONSOLE, STE JMP TABLE TO JUST OUTPUT LINE
		;
		CALL	LIST_INIT1
		MOV	LOUTALL,EAX
		MOV	EAX,ECX
		RET

LIST_INIT	ENDP

if	fg_segm

		PUBLIC	IMP_INIT

IMP_INIT	PROC
		;
		;
		;
		CALL	LIST_INIT1
		CMP	EAX,OFF LST_OUT
		JNZ	L1$
		MOV	EAX,OFF IMP_OUT
L1$:
		MOV	IMP_OUTALL,EAX
		MOV	EAX,ECX
		RET

IMP_INIT	ENDP

endif

if	fg_rom
		PUBLIC	BINOUT_INIT

BINOUT_INIT	PROC

		CALL	LIST_INIT1
		CMP	CX,OFF LST_OUT
		JNZ	1$
		LEA	CX,BIN_OUT
1$:
		MOV	BOUTALL.OFFS,CX
if	@CodeSize
		MOV	BOUTALL.SEGM,AX
endif
		RET

BINOUT_INIT	ENDP

endif


LIST_INIT1	PROC	NEAR
		;
		;EAX IS OUTFILE GINDEX
		;
		;RETURNS:
		;	EAX IS OUTPUT ROUTINE
		;	ECX IS OUTPUT DEVICE
		;
		TEST	EAX,EAX
		JZ	L1$
		CONVERT	EAX,EAX,OUTFILE_GARRAY
		MOV	EAX,[EAX].OUTFILE_STRUCT._OF_FILE_LIST_GINDEX
		MOV	ECX,EAX
		CONVERT	EAX,EAX,_FILE_LIST_GARRAY

		TEST	[EAX].NFN_STRUCT.NFN_FLAGS,MASK NFN_NUL
		JZ	L5$
L1$:
		MOV	EAX,OFF ROOT_RET
		XOR	ECX,ECX
		RET

L5$:
		;
		;NEED TO ALLOCATE BUFFER SPACE LIKE OBJ FILE
		;
		MOV	EAX,ECX
		push	EAX
		call	_open_output
		add	ESP,4
		MOV	[EAX].MYO_STRUCT.MYO_FLUSHBUF,OFF _flush_buffer
		mov	ECX,EAX
		MOV	EAX,OFF LST_OUT
		RET

LIST_INIT1	ENDP


		END

